/*
 * StockModel.h
 *
 *  Created on: 11.02.2009
 *      Author: Konan Andrej
 */

#ifndef STOCKMODEL_H_
#define STOCKMODEL_H_

#include <QAbstractTableModel>

#include "DataBase.h"
#include "Debug.h"

class StockModel : public QAbstractTableModel
{
    Q_OBJECT

private slots:
        void resetModel();
        void changeItemsVector();

public:
	StockModel( DataBase* db, QObject *parent = 0 );
        ~StockModel();

        void SetDatabase( DataBase *db );
        int GetItem( int index, ItemType &item );

	int	rowCount( const QModelIndex &parent ) const;
	int	columnCount( const QModelIndex &parent ) const;
	QVariant data( const QModelIndex &index, int role ) const;
	QVariant headerData( int section, Qt::Orientation orientation,
						 int role ) const;
        //sort table by first column in back order
        void setSortingFlag( bool flag )  { toSortFlag = flag; changeItemsVector();}

        void    sort(int column, Qt::SortOrder order);
        //bool    caseItemType(const ItemType &i1, const ItemType &i2);

	bool insertRows ( int row, int count, const QModelIndex & parent = QModelIndex() );
	bool removeRows ( int row, int count, const QModelIndex & parent = QModelIndex() );


private:
	DataBase* DB;
        QVector<ItemType> items;
        bool toSortFlag;

};

#endif /* STOCKMODEL_H_ */
